<template>
<<<<<<< HEAD
  <div class='container'>题组管理</div>
</template>

<script>
export default {}
=======
  <el-card class="container">
    <!-- 第一层表头 -->
    <div class="diyicengdiv">
      <span style="font-size:12px; color:pink "
        >说明：目前支持学科和关键字条件筛选</span
      >
      <el-button
        class="xinzengshiti"
        icon="el-icon-edit"
        size="mini"
        @click="xzstbtn"
        >新增试题</el-button
      >
    </div>
    <!-- /第一层表头 -->

    <!-- 第二层选择器 -->
    <el-form :model="pageInfo" ref="form" label-width="80px">
      <el-row :gutter="20">
        <!-- 第一行 -->
        <el-col :span="6">
          <el-form-item label="学科">
            <el-select
              @change="handle"
              v-model="pageInfoTwo.subjectID"
              placeholder="请选择"
            >
              <el-option
                v-for="(item, index) in requestParameter.subjectData"
                :key="index"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="二级目录">
            <el-select v-model="tjddxInfo.twocatalog" placeholder="请选择">
              <el-option
                v-for="(item, index) in requestParameter.twocatalog"
                :key="index"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="标签">
            <el-select v-model="tjddxInfo.tags" placeholder="请选择">
              <el-option
                v-for="(item, index) in requestParameter.tags"
                :key="index"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="关键字">
            <el-input
              v-model="pageInfoTwo.keyword"
              placeholder="根据题干搜索"
            ></el-input>
          </el-form-item>
        </el-col>
        <!-- 第二行 -->
        <el-col :span="6">
          <el-form-item label="试题类型">
            <el-select v-model="tjddxInfo.questionType" placeholder="请选择">
              <el-option
                v-for="(item, index) in stlxList"
                :key="index"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="难度">
            <el-select v-model="tjddxInfo.difficulty" placeholder="请选择">
              <el-option
                v-for="(item, index) in ndList"
                :key="index"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="方向">
            <el-select v-model="tjddxInfo.direction" placeholder="请选择">
              <el-option
                v-for="(item, index) in fxList"
                :key="index"
                :label="item"
                :value="index"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="录入人">
            <el-select v-model="tjddxInfo.creator" placeholder="请选择">
              <el-option
                v-for="(item, index) in lrzList"
                :key="index"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <!-- 第三行 -->
        <el-col :span="6">
          <el-form-item label="题目备注">
            <el-input
              v-model="tjddxInfo.remarks"
              placeholder="请输入"
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="企业简称">
            <el-input
              v-model="tjddxInfo.shortname"
              placeholder="请输入"
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="城市">
            <el-select
              v-model="tjddxInfo.csList"
              class="jilian1"
              placeholder="请选择"
              @change="csxsHandle"
            >
              <el-option
                v-for="item in csSelect.csList"
                :key="item"
                :label="item"
                :value="item"
              ></el-option>
            </el-select>
            <el-select
              v-model="tjddxInfo.csxsList"
              class="jilian2"
              placeholder="请选择"
            >
              <el-option
                v-for="item in csSelect.csxsList"
                :key="item"
                :label="item"
                :value="item"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item class="youxiajiaoanniu">
            <el-button @click="clearbtn">清除</el-button>
            <el-button @click="sousuobtn" type="primary">搜索</el-button>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <!-- /第二层选择器 -->
    <!-- 第三层提示行 -->
    <el-alert :title="`数据一共${countes}条`" type="info" show-icon></el-alert>
    <!-- /第三层提示行 -->
    <!-- 第四层Table表格 -->
    <el-table :data="tableData" stripe style="width: 100%" class="table_base">
      <el-table-column
        label="试题编号"
        prop="number"
        width="215"
      ></el-table-column>
      <el-table-column prop="subjectID" label="学科" width="50">
        <template slot-scope="scope">
          <span v-if="scope.row.subjectID === 1">java</span>
          <span v-else>前端</span>
        </template>
      </el-table-column>
      <el-table-column prop="catalogID" label="目录" width="100">
        <template slot-scope="scope">
          <span v-if="scope.row.catalogID === 1">Java基础</span>
          <span v-else-if="scope.row.catalogID === 2">JavaWEB</span>
          <span v-else-if="scope.row.catalogID === 5">css基础</span>
          <span v-else>js基础</span>
        </template>
      </el-table-column>
      <el-table-column prop="questionType" label="题型" width="50">
        <template slot-scope="scope">
          <span v-if="scope.row.questionType === '1'">单选</span>
          <span v-else-if="scope.row.questionType === '2'">多选</span>
          <span v-else>简答</span>
        </template>
      </el-table-column>
      <el-table-column label="题干" width="200">
        <template slot-scope="scope">{{
          scope.row.question | html2Text()
        }}</template>
      </el-table-column>
      <el-table-column label="录入时间" width="200">
        <template slot-scope="scope">{{
          scope.row.addDate | parseTimeByString()
        }}</template>
      </el-table-column>
      <el-table-column prop="difficulty" label="难度">
        <template slot-scope="scope">
          <span v-if="scope.row.difficulty === '1'">简单</span>
          <span v-else-if="scope.row.difficulty === '2'">一般</span>
          <span v-else>困难</span>
        </template>
      </el-table-column>
      <el-table-column prop="creator" label="录入人"></el-table-column>
      <el-table-column label="操作" width="200">
        <template slot-scope="scope">
          <el-tooltip
            :enterable="false"
            class="ylitem"
            effect="light"
            content="预览"
            placement="bottom"
          >
            <el-button
              @click="previewBtn(scope.row)"
              size="mini"
              icon="el-icon-view"
              type="primary"
              circle
              plain
            ></el-button>
          </el-tooltip>
          <el-tooltip
            :enterable="false"
            class="ylitem"
            effect="light"
            content="修改"
            placement="bottom"
          >
            <el-button
              size="mini"
              icon="el-icon-edit"
              type="success"
              circle
              plain
              @click="modify(scope.row.id)"
            ></el-button>
          </el-tooltip>
          <el-tooltip
            :enterable="false"
            class="ylitem"
            effect="light"
            content="删除"
            placement="bottom"
          >
            <el-button
              @click="deleteUser(scope.row.id)"
              size="mini"
              icon="el-icon-delete"
              type="danger"
              circle
              plain
            ></el-button>
          </el-tooltip>
          <el-tooltip
            :enterable="false"
            class="ylitem"
            effect="light"
            content="加入精选"
            placement="bottom"
          >
            <el-button
              @click="jrjxbtn(scope.row.id)"
              size="mini"
              icon="el-icon-check"
              type="warning"
              circle
              plain
            ></el-button>
          </el-tooltip>
        </template>
      </el-table-column>
    </el-table>
    <!-- /第四层Table表格 -->
    <!-- 第五层分页 -->
    <div class="block">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="pageInfo.page"
        :page-sizes="[2, 5, 7, 10]"
        :page-size="pageInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="countes"
      ></el-pagination>
    </div>
    <!-- /第五层分页 -->
    <!-- 预览对话弹框 -->
    <questions-preview
      ref="timuyulanrefs"
      :previewData="previewInfo"
      :daanjiexiA="daanjiexi"
    ></questions-preview>
    <!-- /预览对话弹框 -->
  </el-card>
</template>

<script>
import { list, remove, choiceAdd, detail } from '@/api/hmmm/questions'
import {
  questionType,
  difficulty,
  direction,
  Inputer
} from '@/api/hmmm/constants'
import { simple as subjectList } from '@/api/hmmm/subjects'
import { simple as twoCatalog } from '@/api/hmmm/directorys'
import { simple as bq } from '@/api/hmmm/tags'
import { provinces, cityss } from '@/api/hmmm/citys'
import questionsPreview from '../components/questions-preview'

export default {
  name: 'JiChuTiKu',
  components: {
    questionsPreview
  },
  props: {},
  data() {
    return {
      tableData: [], // 获取到的接口总数据
      countes: 0, // 获取总页数
      pageInfo: {
        pagesize: 2,
        page: 1
      },
      pageInfoTwo: {
        pagesize: 2,
        page: 1,
        subjectID: '', // 学科列表
        keyword: '' // 关键字
      },
      requestParameter: {
        subjectData: [], // 学科列表
        twocatalog: [], // 二级目录
        tags: [], // 标签
        stlxList: [] // 试题类型
      },
      tjddxInfo: {
        subjectID: '', // 学科列表
        twocatalog: '', // 二级目录
        tags: '', // 标签
        keyword: '', // 关键字
        questionType: '', // 试题类型
        difficulty: '', // 难度
        direction: '', // 方向
        creator: '', // 录入人
        remarks: '', // 题目备注
        shortname: '', // 企业简称
        csList: '', // 城市
        csxsList: '' // 城市下市
      },
      stlxList: questionType,
      ndList: difficulty,
      fxList: direction,
      lrzList: Inputer,
      // 双省联动
      csSelect: {
        csList: provinces,
        csxsList: []
      },
      previewInfo: {
        questionType: '', // 题型
        id: '', // 编号
        difficulty: '', // 难度
        tags: '', // 标签
        subject: '', // 学科
        catalogID: '', // 目录
        direction: '', // 方向
        question: '' // 题干
      },
      daanjiexi: {
        answer: '', // 答案解析
        remarks: '', // 题目备注
        videoURL: '', // 视频答案
        questionType: '', // 题型
        options: [] // 选项
      }
    }
  },
  computed: {},
  watch: {},
  created() {
    this.getList()
  },
  mounted() {},
  methods: {
    csxsHandle() {
      cityss.forEach(item => {
        if (item.city === this.tjddxInfo.csList) {
          this.csSelect.csxsList = item.area
        }
      })
    },
    // 跳转页面
    xzstbtn() {
      this.$router.push({ name: 'questions-new', params: { type: 0 } })
    },
    // 基础题库列表
    async getList(val) {
      const shishi =
        this.pageInfoTwo.subjectID === '' ? this.pageInfo : this.pageInfoTwo
      try {
        const { data } = await list(shishi)
        this.countes = data.counts
        this.tableData = data.items // 获取到的接口总数据
        // 学科列表
        const { data: xklb } = await subjectList()
        this.requestParameter.subjectData = xklb
      } catch (err) {
        this.$message.error('获取数据失败')
      }
    },
    async handle(e) {
      const { data: ejml } = await twoCatalog({
        subjectID: e
      })
      this.requestParameter.twocatalog = ejml
      const { data: jgbq } = await bq({
        subjectID: e
      })
      this.requestParameter.tags = jgbq
    },
    // 页码按钮
    handleSizeChange(val) {
      this.pageInfo.pagesize = val
      this.getList()
    },
    // 页码按钮
    handleCurrentChange(val) {
      this.pageInfo.page = val
      this.getList()
    },
    // 点击删除列表行
    deleteUser(id) {
      this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(async () => {
          await remove({ id })
          this.tableData.splice(id, 1)
          this.getList()
          this.$message.success('删除成功')
        })
        .catch(() => {
          this.$message.info('已取消删除')
        })
    },
    // 点击删除按钮
    clearbtn() {
      this.tjddxInfo = {}
      this.pageInfoTwo.subjectID = '' // 学科列表
      this.pageInfoTwo.keyword = '' // 关键字
      this.getList()
    },
    // 搜索按钮
    sousuobtn() {
      this.getList(this.pageInfoTwo)
    },
    // 修改按钮
    modify(val) {
      this.$router.push({ name: 'questions-new', params: { id: val, type: 1 } })
    },
    // 加入精选按钮
    jrjxbtn(id) {
      console.log(id)
      this.$confirm('此操作将该题目加入精选, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'info'
      })
        .then(() => {
          choiceAdd({
            id: id,
            choiceState: 1
          })
          this.$message({
            type: 'success',
            message: '加入精选题库成功!'
          })
          this.$router.push('/questions/choice')
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          })
        })
    },

    async previewBtn(val) {
      const { data: res } = await detail(val)
      console.log(res)
      this.daanjiexi = res
      this.$refs.timuyulanrefs.timuyulan()
      this.previewInfo = val
    }
  }
}
>>>>>>> 99b581ad90efc8af6413e4097d13ec8f4855db58
</script>

<style scoped lang='less'></style>
